﻿using System;
using System.IO;
using UnityEngine;

// Token: 0x02000002 RID: 2
public class AssetBundleController
{
	// Token: 0x17000001 RID: 1
	// (get) Token: 0x06000001 RID: 1 RVA: 0x00002050 File Offset: 0x00000250
	// (set) Token: 0x06000002 RID: 2 RVA: 0x00002058 File Offset: 0x00000258
	public string directory { get; set; }

	// Token: 0x17000002 RID: 2
	// (get) Token: 0x06000003 RID: 3 RVA: 0x00002064 File Offset: 0x00000264
	// (set) Token: 0x06000004 RID: 4 RVA: 0x0000206C File Offset: 0x0000026C
	public string assetBundleName { get; set; }

	// Token: 0x06000005 RID: 5 RVA: 0x00002078 File Offset: 0x00000278
	public T LoadAsset<T>(string assetName) where T : UnityEngine.Object
	{
		if (typeof(T) == typeof(Texture2D) && (this.assetBundleName.Contains("thumnbnail/thumbnail_") || this.assetBundleName.Contains("thumnbnail/thumnbs_")))
		{
			string text = this.directory + "/thumnbnail_R/" + assetName + ".png";
			if (File.Exists(text))
			{
				Console.WriteLine("Load thumb:" + text);
				return (T)((object)AssetBundleController.LoadPNG(text));
			}
		}
		if (this.assetBundle != null)
		{
			return this.assetBundle.LoadAsset<T>(assetName);
		}
		return default(T);
	}

	// Token: 0x06000006 RID: 6 RVA: 0x00002120 File Offset: 0x00000320
	private static Texture2D LoadPNG(string file)
	{
		byte[] array;
		using (BinaryReader binaryReader = new BinaryReader(new FileStream(file, FileMode.Open, FileAccess.Read)))
		{
			try
			{
				array = binaryReader.ReadBytes((int)binaryReader.BaseStream.Length);
			}
			catch (Exception message)
			{
				GlobalData.Debug_LogWarning(message);
				array = null;
			}
			binaryReader.Close();
		}
		if (array == null)
		{
			return null;
		}
		Texture2D texture2D = new Texture2D(1, 1, TextureFormat.ARGB32, false);
		texture2D.LoadImage(array);
		return texture2D;
	}

	/// <summary>打开文件</summary>
	public bool OpenFromFile(string directory, string assetBundleName)
	{
		this.directory = directory;
		this.assetBundleName = assetBundleName;
		string text = this.directory + "/" + this.assetBundleName;
		this.assetBundle = null;
		if (File.Exists(text))
		{
			this.assetBundle = AssetBundle.LoadFromFile(text);
		}
		else
		{
			GlobalData.Debug_Log("文件不存在：" + text);
		}
		return this.assetBundle != null;
	}

	// Token: 0x06000008 RID: 8 RVA: 0x00002240 File Offset: 0x00000440
	public void Close(bool unloadAllLoadedObjects = false)
	{
		try
		{
			if (this.assetBundle != null)
			{
				this.assetBundle.Unload(unloadAllLoadedObjects);
			}
		}
		catch (Exception arg)
		{
			GlobalData.Debug_LogError(this.assetBundleName + ":" + arg);
		}
	}

	// Token: 0x06000009 RID: 9 RVA: 0x00002294 File Offset: 0x00000494
	public AssetBundleController()
	{
	}

	// Token: 0x0600000A RID: 10 RVA: 0x0000229C File Offset: 0x0000049C
	public AssetBundleController(bool isSimulate)
	{
		this.assetBundleName = string.Empty;
		this.directory = string.Empty;
		this.isSimulate = isSimulate;
	}

	// Token: 0x17000003 RID: 3
	// (get) Token: 0x0600000B RID: 11 RVA: 0x000022C4 File Offset: 0x000004C4
	// (set) Token: 0x0600000C RID: 12 RVA: 0x000022CC File Offset: 0x000004CC
	public bool isSimulate { get; private set; }

	// Token: 0x17000004 RID: 4
	// (get) Token: 0x0600000D RID: 13 RVA: 0x000022D8 File Offset: 0x000004D8
	public bool isOpened
	{
		get
		{
			return this.assetBundle != null;
		}
	}

	// Token: 0x0600000E RID: 14 RVA: 0x000022E8 File Offset: 0x000004E8
	~AssetBundleController()
	{
		if (this.isOpened)
		{
			GlobalData.Debug_LogError("忘记关闭资产包:" + this.assetBundleName);
		}
	}

	// Token: 0x0600000F RID: 15 RVA: 0x00002334 File Offset: 0x00000534
	public T LoadAndInstantiate<T>(string assetName) where T : UnityEngine.Object
	{
		T t = this.LoadAsset<T>(assetName);
		if (t != null)
		{
			return UnityEngine.Object.Instantiate<T>(t);
		}
		return (T)((object)null);
	}

	// Token: 0x06000010 RID: 16 RVA: 0x00002368 File Offset: 0x00000568
	public static AssetBundleController New_OpenFromFile(string directory, string assetBundleName)
	{
		AssetBundleController assetBundleController = new AssetBundleController();
		if (assetBundleController.OpenFromFile(directory, assetBundleName))
		{
			return assetBundleController;
		}
		return null;
	}

	// Token: 0x04000001 RID: 1
	public AssetBundle assetBundle;

	// Token: 0x04000002 RID: 2
	public int MSlotId10;

	// Token: 0x04000003 RID: 3
	public int MSlotId11;

	// Token: 0x04000004 RID: 4
	public int MSlotId13;
}
